package cn.hesion.mergefile.step1;
/**
 * ClassName: MergeInputFormat <br/>
 * Description: <br/>
 * date: 2021/2/4 9:33<br/>
 *
 * @author Hesion<br />
 * @version
 * @since JDK 1.8
 */

import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.BytesWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.InputSplit;
import org.apache.hadoop.mapreduce.JobContext;
import org.apache.hadoop.mapreduce.RecordReader;
import org.apache.hadoop.mapreduce.TaskAttemptContext;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;

import java.io.IOException;

/**
 * @program: ClientDemo
 * @description:
 * @author: hesion
 * @create: 2021-02-04 09:33
 **/
public class MergeInputFormat extends FileInputFormat<Text, BytesWritable> {

    // 设置不进行切分
    @Override
    protected boolean isSplitable(JobContext context, Path filename) {
        return false;
    }

    @Override
    public RecordReader<Text, BytesWritable> createRecordReader(InputSplit split, TaskAttemptContext context) throws IOException, InterruptedException {
        MergeRecordReader recordReader = new MergeRecordReader();
        recordReader.initialize(split,context);

        return recordReader;
    }
}
